import React, { PropTypes } from 'react';
import { Form, Input, Button, Select } from 'antd';
import styles from './Search.less';

const TransferFileSearch = ({
  target, user_id, change_type, useritem_id,
  onSearch,
  onAdd,
  onClear,
  form: {
    getFieldDecorator,
    validateFields,
    getFieldsValue,
    resetFields,
    },
  }) => {
  function handleSubmit(e) {
    e.preventDefault();
    validateFields((errors) => {
      if (!!errors) {
        return;
      }
      onSearch(getFieldsValue());
    });
  }

  function handleReset(e) {
    e.preventDefault();
    resetFields();
    onClear();
    //state.total = 0;
  }

  return (
    <div className={styles.normal}>
      <div className={styles.search}>
        <Form inline onSubmit={handleSubmit}>
          {/*<Form.Item
            label="用户ID"
          >
            {getFieldDecorator('user_id', {
              initialValue: user_id || '',
            })(
              <Input type="text" />
            )}
          </Form.Item>
          <Form.Item
            label="持有量ID"
          >
            {getFieldDecorator('useritem_id', {
              initialValue: useritem_id || '',
            })(
              <Input type="text" />
            )}
          </Form.Item>
          <Form.Item
            label="使用对象描述">
            {getFieldDecorator('target', {
              initialValue: target || '',
            })(
              <Input type="text" />
            )}
          </Form.Item>
          <Form.Item
            label="变化类别"
          >
            {getFieldDecorator('change_type', {
              initialValue: change_type || '',
            })(
              <Select>
                <Select.Option value="">请选择</Select.Option>
                <Select.Option value="1">购买</Select.Option>
                <Select.Option value="2">使用</Select.Option>
                <Select.Option value="3">人工变更</Select.Option>
              </Select>
            )}
          </Form.Item>*/}
          <Button style={{ marginRight: '10px' }} type="primary" htmlType="submit">搜索</Button>
          <Button style={{ marginRight: '10px' }} type="ghost" onClick={handleReset}>清空</Button>
        </Form>
      </div>
      {/*<div className={styles.create}>
        <Button type="ghost" onClick={onAdd}>添加</Button>
      </div>*/}
    </div>
  );
};

TransferFileSearch.propTypes = {
  form: PropTypes.object.isRequired,
  onSearch: PropTypes.func,
  onAdd: PropTypes.func,
  target: PropTypes.string,
  user_id: PropTypes.string,
  change_type: PropTypes.string,
  useritem_id: PropTypes.string,
};

export default Form.create()(TransferFileSearch);
